<template>
  <div class="box">
    <el-form size="medium"  ref="itemForm" :model="obj" :rules="itemRules" label-width="100px">

      <el-form-item label="订单编号">{{orderno}}</el-form-item>
      <el-form-item label="订单价格">{{money}}</el-form-item>
      <el-form-item label="变化类型">
        <el-radio-group v-model="obj.type">
          <el-radio :label="0">增加</el-radio>
          <el-radio :label="1">减少</el-radio>
          <!-- <el-radio :label="2">最终积分</el-radio> -->
        </el-radio-group>
      </el-form-item>

      <el-form-item label="变更金额" prop="money">
        <el-input placeholder="变更金额" v-model="obj.money" style="width:200px;">
          <template slot="append">金额</template>
        </el-input>
      </el-form-item>

     <!-- <el-form-item label="操作备注" prop="remark">
        <el-input placeholder="变更备注" v-model="obj.remark" type="textarea" rows="2"></el-input>
      </el-form-item> -->

      <el-form-item label="管理员密码" prop="password">
        <el-input placeholder="请输入操作员密码" show-password v-model="obj.password"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="saveData">保存数据</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>
<script>
import {
  getOrder,
  changeMoney
} from '@/api/shop/order';

export default {
  name: 'editMoney',
  data() {
    return {
      isLoading: false,
      orderno:'',
      money:'',
      obj:{
        id:'',
        type:0,//变化类型:0:增加,1:减少,2:最终金额
        money:0,
        password:'',
        update_time:''
      },
      itemRules: {
        remark: [{
          required: true,
          message: '请输入备注'
        }],
        password: [{
          required: true,
          message: '请输入管理员密码'
        }],
      money: [{
        required: true,
        message: '请输入变更金额'
      }]
      }
    }
  },
  created(){},
  methods: {
    //初始化
    init(id){
      this.isEdit = true;
      this.isLoading = true;
      getOrder(id).then(res => {
        this.isLoading = false;
        let o = res.msg;
        //赋值数据
        this.orderno = o.order_no;
        this.money=o.money
        this.obj.id = o.id;
        this.obj.update_time = o.update_time;
      }).catch(e => {
        this.isLoading = false;
      })
    },
    //保存数据(修改发货地址)
    saveData(){
      this.$refs.itemForm.validate(valid => {
        if (valid) {
          let o = {...this.obj};

          //特殊处理字段
           o.num = parseFloat(o.num);
          this.isLoading = true;
          changeMoney(o).then(res => {
            this.isLoading = false;
            this.$emit('success');
          }).catch(e => {
            this.isLoading = false;
          })
        } else {
          //console.log('error')
          return false
        }
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.el-form-item{
  margin-bottom:15px;
}
</style>
